/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.jims.api.v1.controller.sync;

import com.baomidou.kisso.my.controller.BaseController;
import com.jims.master.common.data.Message;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.SecurityUtil;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.patient.RecordUpload.service.RecordUploadService;
import com.jims.master.modules.patient.health.entity.DailyCheck;
import com.jims.master.modules.sync.entity.PatVisit;
import com.jims.master.modules.sync.entity.PatientDateList;
import com.jims.master.modules.sync.service.ClinicMasterService;
import com.jims.master.modules.sync.service.PatVisitService;
import com.jims.master.modules.sync.service.PatientDateListService;
import com.jims.master.modules.tj.service.TjHzRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 就诊记录时间轴Controller
 * @author xueyx
 * @version 2017-12-02
 */
@RestController
@RequestMapping(value = "/patientDateList")
public class PatientDateListController extends BaseController {

	@Autowired
	private PatientDateListService patientDateListService;

    @Autowired
    private PatVisitService patVisitService;
    @Autowired
    private ClinicMasterService clinicMasterService;
    @Autowired
    private RecordUploadService recordUploadService;
    @Autowired
    private TjHzRecordService tjHzRecordService;
	
	@ModelAttribute
	public PatientDateList get(@RequestParam(required=false) String id) {
		PatientDateList entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = patientDateListService.get(id);
		}
		if (entity == null){
			entity = new PatientDateList();
		}
		return entity;
	}


    /***
     * 病历时间轴
     * @param idCard
     * @return
     */
    @RequestMapping(value = "/V100/getListInfo",method ={RequestMethod.GET,RequestMethod.POST})
    public String getInfo(String idCard,String isPublic,@RequestParam(required = true)String pageNo, String pageSize, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<PatientDateList> patientDateLists;
        if(StringUtils.isNotBlank(idCard)) {
            Page<PatientDateList> page = new Page<PatientDateList>();
            Map<String ,Object> map1 = new HashMap<String, Object>();
            PatientDateList patientDateList = new PatientDateList();
            patientDateList.setIdCard(idCard);
            patientDateList.setIsPublic(isPublic);
            map1.put("patientDateList",patientDateList);
            map1.put("pageNo",pageNo);
            map1.put("pageSize",pageSize);
            page=patientDateListService.findList(new Page<PatientDateList>(request,response),map1);
            patientDateLists = page.getList();
            map.put("patientDateLists", patientDateLists);
        }else{
            patientDateLists = null;
        }
        Message mes = new Message();
        mes.setData(patientDateLists);
        return SecurityUtil.encryptMsgData(mes);
    }

    /***
     * 病历时间轴公开开关
     * @param id
     * @param type
     * @return
     */
    @RequestMapping(value = "/V100/setIspublic",method ={RequestMethod.GET,RequestMethod.POST})
    public String setIspublic(String id,String type,String state) {
        int result = Integer.valueOf(type);
        int j =0;
        switch(result)
        {
            case 0:
                j=patVisitService.updatePublic(state,id);
                break;
            case 1:
                j=clinicMasterService.updatePublic(state,id);
                break;
            case 2:
                j=recordUploadService.updatePublic(state,id);
                break;
            case 3:
                j=tjHzRecordService.updatePublic(state,id);
                break;
        }
        Message mes = new Message();
        if(j>0){
            mes.setData("成功");
        }else {
            mes.setData("失败");
        }
        return SecurityUtil.encryptMsgData(mes);
    }
}